package com.yanqu.road.entity.activity.fivehero;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.fivehero.config.*;
import com.yanqu.road.entity.activity.fivehero.cross.CrossFiveHeroBookData;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FiveHeroConfig {

    private RandomHelper randomHelper = new RandomHelper();

    private ActivityInfo activityInfo;

    private Map<Integer, FiveHeroTypeConfig> typeConfigMap;
    private Map<Integer, FiveHeroCityConfig> cityConfigMap;
    private Map<Integer, FiveHeroBuffConfig> buffConfigMap;
    private Map<Integer, FiveHeroEventConfig> eventConfigMap;
    private Map<Integer, FiveHeroBookConfig> bookConfigMap;
    private Map<Integer, FiveHeroBanditConfig> banditConfigMap;
    private Map<Integer, FiveHeroTechConfig> techConfigMap;
    private Map<Integer, FiveHeroOrderConfig> orderConfigMap;
    private Map<Integer, FiveHeroTitleConfig> titleConfigMap;

    //报名时间
    private List<Long> registerTimeList = new ArrayList<>();
    //每日战斗时间
    private Map<Integer,List<Long>> goingTimeList = new ConcurrentHashMap<>();
    //主城开放时间
    private Map<Integer,List<Long>> mainCityTimeList = new ConcurrentHashMap<>();

    private int popularityItemId;
    //总的商会数量
    private int unionCount;
    //阵营数量
    private int campCount;
    //体力恢复道具
    private int energItemId;
    //残卷道具
    private int bookItemId;
    //体力恢复时间
    private int energyCdTime;
    //体力每次时间恢复多少
    private int energyCdNum;
    //体力上限
    private int energyMax;

    //现金礼包持续时间
    private long rmbMallTime = 60000;
    //战令产出时间间隔
    private int tokenGetRewardCd = 60;

    //城主
    private String titleMailTitle = "";
    private String titleMailContent = "";

    private Map<Integer,List<Integer>> bigWorshipRewardMap;
    private Map<Integer,List<Integer>> smallWorshipRewardMap;

    //跑马灯
    private int lampNum;//跑马灯保留条数
    private int lampChangeON = 0;
    private int lampKillON = 0;
    private int lampKillNum = 0;
    //城池类型
    private Map<Integer,Integer> lampKillNumMap = new ConcurrentHashMap<>();
    private int lampTokenON = 0;
    private int lampTokenNum = 0;
    private int lampTokenScoreON = 0;
    private int lampTokenScoreMin = 0;
    private int lampTokenScoreMax = 0;

    private int cityChangeON = 0;
    private int cityKillON = 0;
    private int cityKillNum = 0;
    private int cityTokenON = 0;
    private int cityTokenNum = 0;
    private int cityReportNum = 0;

    private int systemChangeON = 0;
    private int systemKillON = 0;
    private int systemKillNum = 0;
    //城池类型
    private Map<Integer,Integer> systemKillNumMap = new ConcurrentHashMap<>();
    private int systemTokenON = 0;
    private int systemTokenNum = 0;

    //阵营内的自己的城池被占领
    private int systemCampON = 0;

    //聊天数量 阵营聊天数量 系统
    private int chatNum = 50;

    //玩家占领后的必出前几门客数，各个职业
    private int makePvpKillPatronsNum = 0;
    //用来随机的基础每个玩家职业门客的前几的
    private int makePvpTopPatronsNum = 0;
    //山贼取的前多少门客
    private int makeBanditTopPatronsNum = 0;

    //守军自动复活时间 s
    private int defPatronsReviveTime;
    //每次自动复活多少个
    private int defPatronsReviveNum;

    //同步门客战力cd时间 s
    private int syncPatronsCd;

    //不同地块获得声望连胜值
    private List<Integer> popList;
    //pvp连胜名望最大值（一级地块|二级地块|三级地块）
    private List<Integer> popMaxList;
    //算声望用到的四个参数
    private List<Integer> popParamList;
    //计算掉血的参数
    private List<Integer> attParamList;

    //城主是不是要开起来
    private int openCityLord;

    //洛阳免费攻打次数
    private int luoYangFreeAttNum;
    //洛阳攻打复活道具
    private int luoYangAttItem;
    //洛阳攻打复活道具
    private List<Integer> luoYangAttCostList;
    //洛阳结束积分上限
    private int luoYangOverScore;

    private String group = ""; // 商会特殊分组范围

    private List<Integer> secondMatchRanges = new ArrayList<>(); // 商会特殊分组范围

    //地块士气加成
    private Map<Integer,Integer> moraleMap = new ConcurrentHashMap<>();

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public void initConfig(Map<String, ActivityConfig> activityConfigMap,
                           Map<Integer, FiveHeroTypeConfig> tmptypeConfigMap,
                           Map<Integer, FiveHeroCityConfig> tmpCityConfigMap,
                           Map<Integer, FiveHeroBuffConfig> tmpBuffConfigMap,
                           Map<Integer, FiveHeroEventConfig> tmpEventConfigMap,
                           Map<Integer, FiveHeroBookConfig> tmpBookConfigMap,
                           Map<Integer, FiveHeroBanditConfig> tmpBanditConfigMap,
                           Map<Integer, FiveHeroTechConfig> tmpTechConfigMap,
                           Map<Integer, FiveHeroOrderConfig> tmpOrderConfigMap,
                           Map<Integer, FiveHeroTitleConfig> tmpTitleConfigMap) {

        typeConfigMap = tmptypeConfigMap;
        cityConfigMap = tmpCityConfigMap;
        buffConfigMap = tmpBuffConfigMap;
        eventConfigMap = tmpEventConfigMap;
        bookConfigMap = tmpBookConfigMap;
        banditConfigMap = tmpBanditConfigMap;
        techConfigMap = tmpTechConfigMap;
        orderConfigMap = tmpOrderConfigMap;
        titleConfigMap = tmpTitleConfigMap;

        List<Integer> tempIntList = new ArrayList<>();
        List<String> tempStrList = new ArrayList<>();

        energItemId = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ITEM_ENERGY.getName()).getIntValue();
        bookItemId = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ITEM_CLASSICS_FRAGMENTS.getName()).getIntValue();
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_CREATE_TEAM_TIME.getName()).getIntListValue(";");
        long gameStartTime = activityInfo.getBeginTime() * 1000;
        if(tempIntList.size() > 0){
            //开始时间
            registerTimeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(1) * DateHelper.HOUR_MILLIONS);
            //结束时间
            registerTimeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(2) * DateHelper.HOUR_MILLIONS);
        }

        tempStrList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_FIRST_STAGE_TIME.getName()).getStringListValue("\\|");
        for(String strInfo : tempStrList){
            tempIntList = StringUtils.stringToIntegerList(strInfo,";");
            List<Long> timeList = new ArrayList<>();
            //开始时间
            timeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(1) * DateHelper.HOUR_MILLIONS);
            //结束时间
            timeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(2) * DateHelper.HOUR_MILLIONS);

            goingTimeList.put(tempIntList.get(0),timeList);
        }

        tempStrList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SECOND_STAGE_TIME.getName()).getStringListValue("\\|");
        for(String strInfo : tempStrList){
            tempIntList = StringUtils.stringToIntegerList(strInfo,";");
            List<Long> timeList = new ArrayList<>();
            //开始时间
            timeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(1) * DateHelper.HOUR_MILLIONS);
            //结束时间
            timeList.add(gameStartTime + (tempIntList.get(0) - 1) * DateHelper.DAY_MILLIONS + tempIntList.get(2) * DateHelper.HOUR_MILLIONS);

            mainCityTimeList.put(tempIntList.get(0),timeList);
        }

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_CAMP_RULE.getName()).getIntListValue(";");
        unionCount = tempIntList.get(0);
        campCount = tempIntList.get(1);

        energyCdTime = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ENERGY_CD.getName()).getIntValue();
        energyCdNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ENERGY_CD_NUM.getName()).getIntValue();
        energyMax = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ENERGY_LIMIT.getName()).getIntValue();


        tokenGetRewardCd = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SANTO_ORDER_RECOVER_CD.getName()).getIntValue();
        rmbMallTime = activityConfigMap.get(eActivityConfigType.FIVE_HERO_RMB_MALL_TIME.getName()).getLongValue() * DateHelper.MINUTE_MILLIONS;

        popularityItemId = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ITEM_SCORE.getName()).getIntValue();

        titleMailTitle = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MAIL_TITLE_FIRST.getName()).getValue();
        titleMailContent = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MAIL_CONTENT_FIRST.getName()).getValue();

        String bigWorshipRewardStr = activityConfigMap.get(eActivityConfigType.FIVE_HERO_WORSHIP_REWARD_PARAM.getName()).getValue();
        bigWorshipRewardMap = getWorshipRewardMap(bigWorshipRewardStr);
        String smallWorshipRewardStr = activityConfigMap.get(eActivityConfigType.FIVE_HERO_DUKE_WORSHIP_REWARD_PARAM.getName()).getValue();
        smallWorshipRewardMap = getWorshipRewardMap(smallWorshipRewardStr);

        lampNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MARQUEE_NUM_MAX.getName()).getIntValue();

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MARQUEE_LAND_CHANGE.getName()).getIntListValue("\\|");
        lampChangeON = tempIntList.get(0);
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MARQUEE_WIN_STREAK.getName()).getIntListValue("\\|");
        lampKillON = tempIntList.get(0);
        lampKillNum = tempIntList.get(1);
        for(int i = 1;i < tempIntList.size();i++){
            lampKillNumMap.put(i,tempIntList.get(i));
        }
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MARQUEE_ORDER_NUM.getName()).getIntListValue("\\|");
        lampTokenON = tempIntList.get(0);
        lampTokenNum = tempIntList.get(1);

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MARQUEE_SPECIAL_PLOT_CAMP_SCORE.getName()).getIntListValue("\\|");
        lampTokenScoreON = tempIntList.get(0);
        lampTokenScoreMin = tempIntList.get(1);
        lampTokenScoreMax = tempIntList.get(2);


        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_BATTLE_REPORT_LAND_CHANGE.getName()).getIntListValue("\\|");
        cityChangeON = tempIntList.get(0);
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_BATTLE_REPORT_WIN_STREAK.getName()).getIntListValue("\\|");
        cityKillON = tempIntList.get(0);
        cityKillNum = tempIntList.get(1);
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_BATTLE_REPORT_ORDER_NUM.getName()).getIntListValue("\\|");
        cityTokenON = tempIntList.get(0);
        cityTokenNum = tempIntList.get(1);
        cityReportNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_BATTLE_REPORT_NUM_MAX.getName()).getIntValue();

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SYSTEM_NOTICE_LAND_CHANGE.getName()).getIntListValue("\\|");
        systemChangeON = tempIntList.get(0);
        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SYSTEM_NOTICE_WIN_STREAK.getName()).getIntListValue("\\|");
        systemKillON = tempIntList.get(0);
        systemKillNum = tempIntList.get(1);
        for(int i = 1;i < tempIntList.size();i++){
            systemKillNumMap.put(i,tempIntList.get(i));
        }

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SYSTEM_NOTICE_ORDER_NUM.getName()).getIntListValue("\\|");
        systemTokenON = tempIntList.get(0);
        systemTokenNum = tempIntList.get(1);

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_CHAT_NOTICE_LOSE_LAND.getName()).getIntListValue("\\|");
        systemCampON = tempIntList.get(0);

        tempIntList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_CHAT_NUM_MAX.getName()).getIntListValue("\\|");
        chatNum = tempIntList.get(0);

        makePvpKillPatronsNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_FINAL_PATRONS_NUM.getName()).getIntValue();
        makePvpTopPatronsNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_PATRONS_NUM.getName()).getIntValue();
        makeBanditTopPatronsNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_BANDIT_PATRONS_NUM.getName()).getIntValue();


        defPatronsReviveTime = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SEIZE_RECOVER_CD.getName()).getIntValue();
        defPatronsReviveNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SEIZE_RECOVER_NUM.getName()).getIntValue();

        syncPatronsCd = activityConfigMap.get(eActivityConfigType.FIVE_HERO_RENEW_POWER_CD.getName()).getIntValue();

        popList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_WIN_POINT_PARAM.getName()).getIntListValue("\\|");
        popParamList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_WIN_FORMULA_PARAM.getName()).getIntListValue("\\|");
        popMaxList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_WIN_SCORE_MAX.getName()).getIntListValue("\\|");

        openCityLord = activityConfigMap.get(eActivityConfigType.FIVE_HERO_KINGS_ACTIVITY.getName()).getIntValue();
        luoYangFreeAttNum = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SPECIAL_PLOT_DISPATCH_NUM_FREE.getName()).getIntValue();
        luoYangAttItem = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SPECIAL_PATRONS_RELIVE_ITEM.getName()).getIntValue();
        luoYangAttCostList = activityConfigMap.get(eActivityConfigType.FIVE_HERO_SPECIAL_PATRONS_RELIVE_ITEM_COST.getName()).getIntListValue("\\|");
        luoYangOverScore = activityConfigMap.get(eActivityConfigType.FIVE_HERO_PECIAL_PLOT_END_COND.getName()).getIntValue();

        if (activityConfigMap.containsKey(eActivityConfigType.FIVE_HERO_GROUP_PARAM.getName())) { // 兼容判断
            group = activityConfigMap.get(eActivityConfigType.FIVE_HERO_GROUP_PARAM.getName()).getValue();
        }

        String attReduceParam = eActivityConfigType.FIVE_HERO_ATTACK_BLOOD_PARAM.getDefaultValue();
        if(activityConfigMap.containsKey(eActivityConfigType.FIVE_HERO_ATTACK_BLOOD_PARAM.getName())){
            attReduceParam = activityConfigMap.get(eActivityConfigType.FIVE_HERO_ATTACK_BLOOD_PARAM.getName()).getValue();
        }
        attParamList = StringUtils.stringToIntegerList(attReduceParam,"\\|");
        String moraleParam = eActivityConfigType.FIVE_HERO_MORALE.getDefaultValue();
        if(activityConfigMap.containsKey(eActivityConfigType.FIVE_HERO_MORALE.getName())){
            moraleParam = activityConfigMap.get(eActivityConfigType.FIVE_HERO_MORALE.getName()).getValue();
        }
        tempStrList = StringUtils.stringToStringList(moraleParam,"\\|");
        for(String tempStr : tempStrList){
            tempIntList = StringUtils.stringToIntegerList(tempStr,";");
            moraleMap.put(tempIntList.get(0),tempIntList.get(1));
        }

        if (!activityConfigMap.containsKey(eActivityConfigType.FIVE_HERO_GROUP_RANGE_PARAM.getName())) {
            setSecondMatchRanges(eActivityConfigType.FIVE_HERO_GROUP_RANGE_PARAM.getDefaultValue());
        } else {
            setSecondMatchRanges(activityConfigMap.get(eActivityConfigType.FIVE_HERO_GROUP_RANGE_PARAM.getName()).getValue());
        }
    }

    //返回士气千分比
    //1;1500|5;1000|9;800|13;500|14;300|24;100
    //大于等于1小于等于5用的1500
    public int getMoraleRate(int distance){
        List<Integer> dList = new ArrayList<>(moraleMap.keySet());
        Collections.sort(dList);
        for(int i = 0; i < dList.size(); i++){
            if(i + 1 < dList.size()){
                if(i == 0){
                    if(distance >= dList.get(i) && distance <= dList.get(i+1)){
                        return moraleMap.get(dList.get(i));
                    }
                }else{
                    if(distance > dList.get(i) && distance <= dList.get(i+1)){
                        return moraleMap.get(dList.get(i));
                    }
                }
            }else{
                if(distance > dList.get(i)){
                    return moraleMap.get(dList.get(i));
                }
            }
        }
        return 1000;
    }

    public int getOpenCityLord() {
        return openCityLord;
    }

    public int getPopValue(int cityType){
        if(cityType <= popList.size()){
            return popList.get(cityType - 1);
        }
        return 1;
    }

    public int getPopMaxValue(int cityType){
        if(cityType <= popMaxList.size()){
            return popMaxList.get(cityType - 1);
        }
        return 1;
    }

    public int getPopParamValue(int index){
        if(index < popParamList.size()){
            return popParamList.get(index);
        }
        return 1;
    }

    public int getAttParamValue(int index){
        if(index < attParamList.size()){
            return attParamList.get(index);
        }
        return 1;
    }

    public int getMakePvpKillPatronsNum() {
        return makePvpKillPatronsNum;
    }

    public int getMakePvpTopPatronsNum() {
        return makePvpTopPatronsNum;
    }

    public int getMakeBanditTopPatronsNum() {
        return makeBanditTopPatronsNum;
    }

    private Map<Integer,List<Integer>> getWorshipRewardMap(String worshipRewardStr){
        Map<Integer, List<Integer>> worshipRewardMap = new ConcurrentHashMap<>();
        for (String tmpParam : StringUtils.stringToStringList(worshipRewardStr, "\\|")) {
            List<String> strList = StringUtils.stringToStringList(tmpParam, "=");
            List<Integer> intList = StringUtils.stringToIntegerList(strList.get(1), ";");
            worshipRewardMap.put(Integer.valueOf(strList.get(0)), intList);
        }
        return worshipRewardMap;
    }

    public Map<Integer, FiveHeroTypeConfig> getTypeConfigMap() {
        return typeConfigMap;
    }

    public FiveHeroTypeConfig getTypeConfig(int type) {
        return typeConfigMap.get(type);
    }

    public FiveHeroTypeConfig getTypeConfigByCityId(int cityId) {
        FiveHeroCityConfig cityConfig = cityConfigMap.get(cityId);
        if(cityConfig != null){
            return typeConfigMap.get(cityConfig.getType());
        }
        return null;
    }

    //比赛第几天了
    public int getMatchDay(){
        long nowTime = System.currentTimeMillis();
        List<Integer> dayList = new ArrayList<>(goingTimeList.keySet());
        Collections.sort(dayList);
        long battleStartZeroTime = DateHelper.getZeroTimeStamp(goingTimeList.get(dayList.get(0)).get(0));
        long todayZeroTime = DateHelper.getZeroTimeStamp(nowTime);
        long day = (todayZeroTime - battleStartZeroTime) / DateHelper.DAY_MILLIONS;
        return (int)(day + 1);
    }

    public int getMatchLastDay(){
        long nowTime = System.currentTimeMillis();
        List<Integer> dayList = new ArrayList<>(goingTimeList.keySet());
        Collections.sort(dayList);
        long battleStartZeroTime = DateHelper.getZeroTimeStamp(goingTimeList.get(dayList.get(0)).get(0));
        long lastDodayZeroTime = DateHelper.getZeroTimeStamp(goingTimeList.get(dayList.get(dayList.size() - 1)).get(0));
        long day = (lastDodayZeroTime - battleStartZeroTime) / DateHelper.DAY_MILLIONS;
        return (int)(day + 1);
    }

    //活动第几天了
    private int getActivityDay(){
        long nowTime = System.currentTimeMillis();
        long acStartZeroTime = DateHelper.getZeroTimeStamp(activityInfo.getBeginTime() * 1000);
        long todayZeroTime = DateHelper.getZeroTimeStamp(nowTime);
        long day = (todayZeroTime - acStartZeroTime) / DateHelper.DAY_MILLIONS;
        return (int)(day + 1);
    }

    //判断当前今天的城市开始战斗时间
    public long getTodayOutSideBeginTime(){
        //第几天了
        int day = getActivityDay();
        if(goingTimeList.containsKey(day)){
            List<Long> timeList = goingTimeList.get(day);
            return timeList.get(0);
        }else{
            return 0;
        }
    }

    //判断当前今天的主城开始战斗时间
    public long getTodayInSideBeginTime(){
        //第几天了
        int day = getActivityDay();
        if(mainCityTimeList.containsKey(day)){
            List<Long> timeList = mainCityTimeList.get(day);
            return timeList.get(0);
        }else{
            return 0;
        }
    }
    //明天什么时候开始
    public long getTomorrowInSideBeginTime(){
        //第几天了
        int day = getActivityDay();
        day = day + 1;
        if(goingTimeList.containsKey(day)){
            List<Long> timeList = goingTimeList.get(day);
            return timeList.get(0);
        }else{
            return 0;
        }
    }

    //洛阳城外的
    public long getTodayOutSideOverTime(){
        //第几天了
        int day = getActivityDay();
        if(goingTimeList.containsKey(day)){
            List<Long> timeList = goingTimeList.get(day);
            return timeList.get(1);
        }else{
            return 0;
        }
    }
    //洛阳城的每日结束
    public long getTodayInSideOverTime(){
        //第几天了
        int day = getActivityDay();
        if(mainCityTimeList.containsKey(day)){
            List<Long> timeList = mainCityTimeList.get(day);
            return timeList.get(1);
        }else{
            return 0;
        }
    }

    public Map<Integer, FiveHeroCityConfig> getCityConfigMap() {
        return cityConfigMap;
    }

    public FiveHeroCityConfig getCityConfig(int cityId) {
        return cityConfigMap.get(cityId);
    }

    public Map<Integer, FiveHeroBuffConfig> getBuffConfigMap() {
        return buffConfigMap;
    }

    public Map<Integer, FiveHeroEventConfig> getEventConfigMap() {
        return eventConfigMap;
    }

    public FiveHeroEventConfig getEventConfig(int eventId) {
        return eventConfigMap.get(eventId);
    }

    public Map<Integer, FiveHeroBookConfig> getBookConfigMap() {
        return bookConfigMap;
    }

    public FiveHeroBookConfig getBookConfig(int bookId) {
        return bookConfigMap.get(bookId);
    }

    public CrossFiveHeroBookData randomBook(Map<Integer, CrossFiveHeroBookData> bookDataMap) {
        CrossFiveHeroBookData newbookData = new CrossFiveHeroBookData();
        newbookData.setId(0);
        List<Integer> hasList = new ArrayList<>();
        for(CrossFiveHeroBookData bookData : bookDataMap.values()){
            if(!hasList.contains(bookData.getId())){
                hasList.add(bookData.getId());
            }
        }
        Map<Integer, FiveHeroBookConfig> useConfigMap = new ConcurrentHashMap<>(bookConfigMap);
        //全部都有了，接下去随便随机
        if(hasList.size() == useConfigMap.size()){
            newbookData.setCanGetReward(false);
        }else{
            for(int bookId : hasList){
                useConfigMap.remove(bookId);
            }
            newbookData.setCanGetReward(true);
        }
        List<Integer> bookList = new ArrayList<>();
        List<Integer> weightList = new ArrayList<>();
        for(int bookId : useConfigMap.keySet()){
            bookList.add(bookId);
            weightList.add(useConfigMap.get(bookId).getWeights());
        }
        int totalWeight = 0;
        for (int weight : weightList) {
            totalWeight += weight;
        }
        int bookId = 0;
        int randomNum = randomHelper.next(0, totalWeight);
        for (int i = 0; i < weightList.size(); i++) {
            int value = weightList.get(i);
            if (randomNum < value) {
                bookId = bookList.get(i);
                newbookData.setId(bookId);
                return newbookData;
            }
            randomNum -= value;
        }
        return newbookData;
    }


    public Map<Integer, FiveHeroBanditConfig> getBanditConfigMap() {
        return banditConfigMap;
    }

    public Map<Integer, FiveHeroTechConfig> getTechConfigMap() {
        return techConfigMap;
    }

    //获得经验最大值
    public int getMaxTechExp() {
        int maxLevel = techConfigMap.size();
        for(int level = maxLevel;level > 0;level--){
            if(techConfigMap.containsKey(level)){
                return techConfigMap.get(level).getCost();
            }
        }
        return 0;
    }

    //技能加成门客固定值
    public int getTechLevel(int expValue) {
        for(int level = techConfigMap.size();level > 0;level--){
            if(techConfigMap.containsKey(level)){
                if(expValue >= techConfigMap.get(level).getCost()){
                    return level;
                }
            }
        }
        return 0;
    }
    //升級了產生的加成百分比
    public int getTechLevelUpAddPer(int oldLevel,int nowLevel) {
        int addPer = 0;
        for(int level = oldLevel + 1;level <= nowLevel;level++){
            FiveHeroTechConfig techConfig = techConfigMap.get(level);
            addPer = addPer + techConfig.getPerthAdd();
        }
        return addPer;
    }

    //技能加成门客固定值
    public int getTechAdd(int expValue) {
        int addValue = 0;
        for(int level = 1;level <= techConfigMap.size();level++){
            if(techConfigMap.containsKey(level)){
                if(expValue >= techConfigMap.get(level).getCost()){
                    addValue = addValue + techConfigMap.get(level).getAdd();
                }
            }
        }
        return addValue;
    }

    //技能加成门客百分值
    public int getTechPerthAdd(int expValue) {
        int addValue = 0;
        for(int level = 1;level <= techConfigMap.size();level++){
            if(techConfigMap.containsKey(level)){
                if(expValue >= techConfigMap.get(level).getCost()){
                    addValue = addValue + techConfigMap.get(level).getPerthAdd();
                }
            }
        }
        return addValue;
    }

    public Map<Integer, FiveHeroOrderConfig> getOrderConfigMap() {
        return orderConfigMap;
    }
    public FiveHeroOrderConfig getOrderConfig(int tokenId) {
        return orderConfigMap.get(tokenId);
    }

    public Map<Integer, FiveHeroTitleConfig> getTitleConfigMap() {
        return titleConfigMap;
    }

    public FiveHeroTitleConfig getTitleConfig(int campId) {
        for(FiveHeroTitleConfig titleConfig : titleConfigMap.values()){
            if(titleConfig.getCampId() == campId){
                return titleConfig;
            }
        }
        return null;
    }

    public ActivityInfo getActivityInfo(){
        return activityInfo;
    }

    public int getActivityId(){
        return activityInfo.getActivityId();
    }


    public int getSignUpUnionCount() {
        return unionCount;
    }

    public int getUnionCount() {
        return unionCount;
    }

    public List<Long> getRegisterTimeList() {
        return registerTimeList;
    }

    public int getCampCount() {
        return campCount;
    }

    public int getEnergyCdTime() {
        return energyCdTime;
    }

    public int getEnergyCdNum() {
        return energyCdNum;
    }

    public int getEnergyMax() {
        return energyMax;
    }

    //根据配置随机一个事件
    public int randomEvent(int cityId) {
        FiveHeroCityConfig cityConfig = getCityConfig(cityId);
        if(typeConfigMap.containsKey(cityConfig.getType())){
            FiveHeroTypeConfig typeConfig = typeConfigMap.get(cityConfig.getType());
            Map<Integer, Integer> eventMap = typeConfig.getEventMap();
            List<Integer> eventList = new ArrayList<>();
            List<Integer> weightList = new ArrayList<>();
            for(int eventId : eventMap.keySet()){
                eventList.add(eventId);
                weightList.add(eventMap.get(eventId));
            }
            int totalWeight = 0;
            for (int weight : weightList) {
                totalWeight += weight;
            }
            int eventId = 0;
            int randomNum = randomHelper.next(0, totalWeight);
            for (int i = 0; i < weightList.size(); i++) {
                int value = weightList.get(i);
                if (randomNum < value) {
                    eventId = eventList.get(i);
                    return eventId;
                }
                randomNum -= value;
            }
        }

        return 0;
    }

    public int getEnergItemId() {
        return energItemId;
    }

    public int getBookItemId() {
        return bookItemId;
    }

    public int getLuoYangId(){
        for(FiveHeroCityConfig cityConfig : cityConfigMap.values()){
            if(cityConfig.getType() == 4){
                return cityConfig.getId();
            }
        }
        return 0;
    }

    public long getRmbMallTime() {
        return rmbMallTime;
    }

    public int getTokenGetRewardCd() {
        return tokenGetRewardCd * 1000;
    }

    public int getPopularityItemId() {
        return popularityItemId;
    }

    public String getTitleMailTitle() {
        return titleMailTitle;
    }

    public String getTitleMailContent() {
        return titleMailContent;
    }

    public Map<Integer, List<Integer>> getBigWorshipRewardMap() {
        return bigWorshipRewardMap;
    }

    public Map<Integer, List<Integer>> getSmallWorshipRewardMap() {
        return smallWorshipRewardMap;
    }


    public int getLampChangeON() {
        return lampChangeON;
    }

    public int getLampKillON() {
        return lampKillON;
    }

    public int getLampKillNum() {
        return lampKillNum;
    }

    public int getLampKillNum(int cityType) {
        if(lampKillNumMap.containsKey(cityType)){
            return lampKillNumMap.get(cityType);
        }
        return lampKillNum;
    }

    public int getLampTokenON() {
        return lampTokenON;
    }

    public int getLampTokenNum() {
        return lampTokenNum;
    }

    public int getLampTokenScoreON() {
        return lampTokenScoreON;
    }

    public int getLampTokenScoreMin() {
        return lampTokenScoreMin;
    }

    public int getLampTokenScoreMax() {
        return lampTokenScoreMax;
    }

    public int getCityChangeON() {
        return cityChangeON;
    }

    public int getCityKillON() {
        return cityKillON;
    }

    public int getCityKillNum() {
        return cityKillNum;
    }

    public int getCityTokenON() {
        return cityTokenON;
    }

    public int getCityTokenNum() {
        return cityTokenNum;
    }

    public int getCityReportNum() {
        return cityReportNum;
    }

    public int getSystemChangeON() {
        return systemChangeON;
    }

    public int getSystemKillON() {
        return systemKillON;
    }

    public int getSystemKillNum() {
        return systemKillNum;
    }

    public int getSystemKillNum(int cityType) {
        if(systemKillNumMap.containsKey(cityType)){
            return systemKillNumMap.get(cityType);
        }
        return systemKillNum;
    }

    public int getSystemTokenON() {
        return systemTokenON;
    }

    public int getSystemTokenNum() {
        return systemTokenNum;
    }

    public int getSystemCampON() {
        return systemCampON;
    }

    public int getChatNum() {
        return chatNum;
    }

    public int getDefPatronsReviveTime() {
        return defPatronsReviveTime * 1000;
    }

    public int getDefPatronsReviveNum() {
        return defPatronsReviveNum;
    }

    public int getSyncPatronsCd() {
        return syncPatronsCd * 1000;
    }

    public int getLampNum() {
        return lampNum;
    }

    public int getLuoYangOverScore() {
        return luoYangOverScore;
    }

    //攻击洛阳消耗
    public int getAttLuoYangCost(int attackTime){
        int param1 = luoYangAttCostList.get(0);
        int param2 = luoYangAttCostList.get(1);
        int param3 = luoYangAttCostList.get(2);
        //免费10次
        if(attackTime <= luoYangFreeAttNum){
            return 0;
        }
        int cost = param1 + (attackTime - luoYangFreeAttNum - 1) * param2;
        return Math.min(cost,param3);
    }

    public int getLuoYangAttItem() {
        return luoYangAttItem;
    }

    public int getCampMainCityId(int campId) {
        for(FiveHeroCityConfig cityConfig : cityConfigMap.values()){
            if(cityConfig.getType() == 5 && cityConfig.getInitialCamp() == campId){
                return cityConfig.getId();
            }
        }
        return 0;
    }

    public List<Integer> getGroupParams() {
        List<Integer> res = new ArrayList<>();

        if (group == null || group.isEmpty()) {
            return res;
        }

        String[] params = group.split(";");
        for (String param : params) {
            res.add(Integer.parseInt(param));
        }

        return res;
    }

    public List<Integer> secondMatchRanges() {
        return new ArrayList<>(secondMatchRanges);
    }

    public void setSecondMatchRanges(String secondMatchRanges) {
        this.secondMatchRanges = StringUtils.stringToIntegerList(secondMatchRanges, ";");
    }
}
